<template>
	<view class="page-box">
		<!-- 搜索框 -->
		<view class="search-box"  @click="GoSearchList">
			<view class="top-box" >
				<image src="../../static/image/search.png"></image>
				<input placeholder="请输入要搜索的商品"  confirm-type="done" />
			</view>
		</view>
		<view class="goods-box">
			<view class="left-box">
				<view v-for="(item,index) in type" :key="index"  @click="ChangeTab(index,item)" :class="id == index ?'type-title2':'type-title'">{{item}}</view>
			</view>
			<view class="right-box">
				<view class="good-title">推荐商品</view>
				<view class="detail-box">
					<view class="gbox" v-for="(good,id) in goodlist" :key="id" v-if="id<3" @click="GoGoodlist(good.title)">
						<image :src="good.image" mode="aspectFit"></image>
						<text>{{good.bp}}</text>
					</view>
				</view>
				<view class="good-title">好评商品</view>
				<view class="detail-box">
					<view class="gbox" v-for="(good,id) in goodlist" :key="id" v-if="id>2&&id<6">
						<image :src="good.image" mode="aspectFit"></image>
						<text>{{good.bp}}</text>
					</view>
				</view>
				<view class="good-title">种草商品</view>
				<view class="detail-box">
					<view class="gbox" v-for="(good,id) in goodlist" :key="id" v-if="id>5">
						<image :src="good.image" mode="aspectFit"></image>
						<text>{{good.bp}}</text>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				type:['手机','食品','服饰','鞋子','彩妆','运动','包包','帽子','生鲜','百货','图书'],
				goodlist:'',
				id:0,
				title:'手机',
			}
		},
		onLoad() {
			this.getList()
		},
		methods: {
			ChangeTab(e,title){
				this.id = e;
				this.title = title;
				this.goodlist = '';
				this.getList()
				},
			// 去搜索列表页	
			GoSearchList(){
				uni.navigateTo({
					url:'/pages/index/search'
				})
				},	
			// 去商品二级页
			GoGoodlist(e){
				console.log(e)
				uni.navigateTo({
					url:'/pages/goods/goods-list'+`?title=${e}`
				})
				},	
			getList(){
				console.log(this.title)
				uni.showLoading({
					title:"加载中"
				})
				uniCloud.callFunction({
					name:'sort',
					data:{
						title:this.title
					},
					success: (rest) => {
						uni.hideLoading()
						console.log('分类获取成功',rest.result.data)
						this.goodlist = rest.result.data
					},
					fail: (err) => {
						uni.hideLoading()
						console.log('分类获取成功',err)
					}
				})
			},
		}
	}
</script>

<style scoped lang="scss">
	.left-box{
		width: 200rpx;
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: space-between;
	}
	.type-title{
		width: 100%;
		height: 80rpx;
		font-size: 32rpx;
		font-weight: 400;
		line-height: 42rpx;
		color: #ff6633;
		opacity: 1;
		display: flex;
		flex-direction: column;
		justify-content: center;
		align-items: center;
	}
	.type-title2{
		background: #ff6633;
		width: 100%;
		font-size: 32rpx;
		font-weight: 400;
		line-height: 42rpx;
		color: #FFFFFF;
		opacity: 1;
		height:80rpx;
		display: flex;
		flex-direction: column;
		justify-content: center;
		align-items: center;
	}
	.search-box{
		background-color: #ff6633;
		padding: 20rpx 20rpx 30rpx 20rpx;
	}	
	.top-box{
		display: flex;
		flex-direction: row;
		align-items: center;
		padding: 20rpx 24rpx;
		background-color: #FFFFFF;
		border-radius: 50rpx;
		image{
			width: 36rpx;
			height: 36rpx;
			margin-right: 26rpx;
			}
		}
	.right-box{
		background-color: #FFFFFF;
		width: 100%;
		}
	.goods-box{
		display: flex;
		flex-direction: row;
		justify-content: space-between;
		height:88vh;
		}
	.good-title{
		font-size: 30rpx;
		font-weight: bold;
		line-height: 40rpx;
		color: #000000;
		opacity: 1;
		width: 100%;
		padding: 30rpx;
		}
	.detail-box{
		display:flex;
		flex-direction: row;
		justify-content: space-between;
		padding: 20rpx 0rpx;
		}
	.gbox{
		width: 33%;
		display: flex;
		flex-direction: column;
		justify-content: center;
		align-items: center;
		image{
			width:100rpx;
			height:100rpx;
			margin-bottom: 12rpx;
		};
		text{
			font-size: 26rpx;
			color: #333333;
			line-height: 30rpx;
		}
	}	
</style>
